package com.twu.biblioteca.service;

import com.twu.biblioteca.model.Library;
import com.twu.biblioteca.model.LibraryService;
import com.twu.biblioteca.model.UserAccount;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by davecroman on 12/09/2014.
 */
public class LibraryServiceManager {

    private final Library library;
    private List<LibraryService> libraryServices;
    private UserAccount user;

    /**
     * Provides services to the specified library.
     * @param library the library to be provided with services
     */
    public LibraryServiceManager(Library library){
        this.library = library;
        initServices();
    }

    private void initServices() {
        libraryServices = new ArrayList<LibraryService>();

        // make sure to add new services in this list
        libraryServices.add(new PersonalProfileService(library));
        libraryServices.add(new DisplayBooksService(library));
        libraryServices.add(new ListMoviesService(library));
        libraryServices.add(new CheckoutBookService(library));
        libraryServices.add(new CheckoutMovieService(library));
        libraryServices.add(new ReturnBookService(library));
    }

    public void setUser(UserAccount user){
        this.user = user;

        for( LibraryService service : libraryServices ){
            service.setUser(user);
        }
    }

    /**
     * Returns all library services.
     */
    public List<LibraryService> getLibraryServices(){
        return libraryServices;
    }
}
